<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Cod_data_entity{
	var $id = 0;
	var $user_id = 0;
	var $price = 0;
	var $coin = 0;
	var $package_id = 0;
	var $created_time = 0;
	var $status = "";
	var $code = "";
	var $redeem_status = "";
	
	function __destruct() {}
	function __construct() {}
    
	function init($cmd, $input)
	{
		$ci=& get_instance();
		
		if($cmd == 'id')
		{
			$result = $ci->db->where('id',$input)->get(TBL_COD)->result();
		}
		else if($cmd == 'code'){
			$result = $ci->db->where('code',$input)->get(TBL_COD)->result();
		}
		else
		{
			return false;
		}
		
		if( !empty($result) )
		{
			$this->id = $result[0]->id;
			$this->user_id = $result[0]->user_id;
			$this->price = $result[0]->price;
			$this->coin = $result[0]->coin;
			$this->package_id = $result[0]->package_id;
			$this->created_time = $result[0]->created_time;
			$this->status = $result[0]->status;
			$this->code = $result[0]->code;
			$this->redeem_status = $result[0]->redeem_status;
			
			return $this;
		}
		return false;
	}
	
	function setUserId($input){ $this->user_id=$input; }
	function setPrice($input){ $this->price=$input; }
	function setCoin($input){ $this->coin=$input; }
	function setPackageId($input){ $this->package_id=$input; }
	function setCreateTime($input){ $this->created_time=$input; }
	function setStatus($input){ $this->status=$input; }
	function setCode($input){ $this->code=$input; }
	function setRedeemStatus($input){ $this->redeem_status=$input; }
	
	function getId(){ return $this->id; }
	function getUserId(){ return $this->user_id; }
	function getPrice(){ return $this->price; }
	function getCoin(){ return $this->coin; }
	function getPackageId(){ return $this->package_id; }
	function getCreateTime(){ return $this->created_time; }
	function getStatus(){ return $this->status; }
	function getCode(){ return $this->code; }
	function getRedeemStatus(){ return $this->redeem_status; }
	
	function update()
	{
		$ci=& get_instance();
		 
		$ci->db->set('user_id', $this->user_id);
		$ci->db->set('price', $this->price);
		$ci->db->set('coin', $this->coin);
		$ci->db->set('package_id', $this->package_id);
		$ci->db->set('created_time', $this->created_time);
		$ci->db->set('status', $this->status);
		$ci->db->set('code', $this->code);
		$ci->db->set('redeem_status', $this->redeem_status);
		
		$ci->db->where('id', $this->id)->update(TBL_COD);
	}
	
	function createNewEntity(){
		$ci=& get_instance();
		
		$ci->db->set('created_time', time());
		$ci->db->insert(TBL_COD);
		
		return $ci->db->insert_id();
	}
	
//end class	
}
